<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
            margin: 0 auto;
            width: 800px;
            height: 400px;
            /* border: 1px solid #000; */
        }

        p {
            width: 198px;
            height: 200px;
            border: 1px solid #000;
            text-align: center;
            line-height: 300px;
            background-color: rgba(0, 0, 0, 0.5);
        }

        .active {
            background-color: rgba(0, 0, 0, 0);
        }
    </style>
</head>

<body>
    <div>
        <p><img src="./1.jpg" alt=""></p>
        <p><img src="./1.jpg" alt=""></p>
        <p><img src="./1.jpg" alt=""></p>
        <p><img src="./1.jpg" alt=""></p>
        <p><img src="./1.jpg" alt=""></p>
        <p><img src="./1.jpg" alt=""></p>
        <p><img src="./1.jpg" alt=""></p>
        <p><img src="./1.jpg" alt=""></p>
    </div>
</body>

</html>
<script>
    window.onload = function () {
        var ps = document.querySelectorAll('p')
    for (var i = 0; i < ps.length; i++) {
        ps[i].onmousemove = function () {
            this.className = 'active'
        }
        ps[i].onmouseout = function () {
            this.className = ''
        }
    }
    }

</script>